/**
 * @author mapeng
 * @version 2017-05-10
 */

(function(doc, win) {

	var pageVariables = {"shopId" : "","type" : "","stepOne" : {}};

	$(doc).on("pageInit", "#weixinOpenStep2Page", function(e, pageId, $page, isBack , isForward) {
		if(isForward == true){
			handleForward();
			return;
		}
		if(isBack == true){
			handleBack();
			return;
		}
		init4Page();
	});
	bindEvents4Page();

	//后退：获取支行搜索结果
	function handleBack(){
		var params = CommonUtil.takeOutParamObject() || {};
		var operation = params.operation;

		if(operation == "branchSearch"){//支行搜索
			var contactLine = params.contactLine;
			var branchBankName = params.branchBankName;
			$("#weixinOpenStep2Page input[name='branchBank']").val(branchBankName);
			$("#weixinOpenStep2Page input[name='contactLine']").val(contactLine);

			listen4Submit();
		}

		params.operation = "";
		CommonUtil.injectParamObject(params);
	}

	//前进：重新获取第一步数据
	function handleForward(){
		var params = CommonUtil.takeOutParamObject() || {};
		pageVariables.shopId = params.shopId;
		pageVariables.type = params.type;
		pageVariables.stepOne = params.stepOne;
	}

	//页面初始化
	function init4Page(){
		var params = CommonUtil.takeOutParamObject() || {};
		pageVariables.shopId = params.shopId;
		pageVariables.type = params.type;
		pageVariables.stepOne = params.stepOne;


		//账户类型
		init4AccountType();

		//开户行地区
		init4AccountDistrict();
	}

	//账户类型
	function init4AccountType(){

		var accountTypeUl = "<ul style='display:none;'>";
		$.each(Constants.weixin.ACCOUNT_TYPE,function(key,value){
			accountTypeUl += "<li data-code='"+value+"' data-val='"+Constants.weixin.getAccountTypeText(value)+"'>"+Constants.weixin.getAccountTypeText(value)+"</li>";
		});
		accountTypeUl += "</ul>";
		$("#weixinOpenStep2Page div[name='accountType']").prepend(accountTypeUl);

		$("#weixinOpenStep2Page div[name='accountType']").children("ul").mobiscroll().treelist({
            "theme": "ios",
            "display": "bottom",
            "lang": "zh",
            "placeholder": "请选择账户",
            "onSelect" : function(valueText,inst){
            	var codeArray = [];
            	var $ul = $this = $(this);
            	$.each(valueText.split("-"),function(index,value){
            		var $li = $ul.children("li[data-val='"+value+"']");
            		codeArray.push($li.attr("data-code"));
            		$ul = $li.children("ul").eq(0);
            	});
            	$this.parent().find("input[type='hidden']").val(codeArray.join(","));

            	//字段切换
            	setAccoutFields(codeArray[0]);

            	listen4Submit();
            }
        });

		//默认“个人账户”
        $("#weixinOpenStep2Page div[name='accountType']").children("ul").mobiscroll("setVal",Constants.weixin.getAccountTypeText(Constants.weixin.ACCOUNT_TYPE.person),true);
        $("#weixinOpenStep2Page div[name='accountType'] input[type='hidden']").val(Constants.weixin.ACCOUNT_TYPE.person);
        setAccoutFields(Constants.weixin.ACCOUNT_TYPE.person);
	}

	//账户类型字段切换
	function setAccoutFields(accountType){
    	if(accountType == Constants.weixin.ACCOUNT_TYPE.person){
    		$("#weixinOpenStep2Page .person").css("display","");
    		$("#weixinOpenStep2Page .company").css("display","none");
    	}else if(accountType == Constants.weixin.ACCOUNT_TYPE.company){
    		$("#weixinOpenStep2Page .person").css("display","none");
    		$("#weixinOpenStep2Page .company").css("display","");
    	}
	}

	//开户行地区
	function init4AccountDistrict(){

        CityUtil.getProvinceCityHtml(function(ul){

        	$("#weixinOpenStep2Page div[name='bankDistrict']").prepend(ul);
        	$("#weixinOpenStep2Page div[name='bankDistrict']").children("ul").mobiscroll().treelist({
	            "theme": "ios",
	            "display": "bottom",
	            "lang": "zh",
	            "placeholder": "请选择省、市",
	            "formatValue" : function(data){
	            	return data.join("-");
	            },
	            "onSelect" : function(valueText,inst){
	            	var codeArray = [];
	            	var $ul = $this = $(this);
	            	$.each(valueText.split("-"),function(index,value){
	            		var $li = $ul.children("li[data-val='"+value+"']");
	            		codeArray.push($li.attr("data-code"));  //data会进行类型转换
	            		$ul = $li.children("ul").eq(0);
	            	});
	            	$this.parent().find("input[type='hidden']").val(codeArray.join(","));

	            	//清空开户银行、支行名称、联行号
	            	$("#weixinOpenStep2Page input[name='branchBank']").val("");
					$("#weixinOpenStep2Page input[name='contactLine']").val("");

	            	init4AccountMainBank(function(){
	            		listen4Submit();
	            	});
            	}
        	});
        });
	}

	//开户主银行
	function init4AccountMainBank(callback){
		var accountBankDistrict = $("#weixinOpenStep2Page div[name='bankDistrict'] input[type='hidden']").val();
		var provinceCode = accountBankDistrict.split(",")[0];
		var cityCode = accountBankDistrict.split(",")[1];
        CommonUtil.sendJsonpRequest({
        // testApi.testGetBankList({
        	"url" : App.serverUrl+"/app/wxAccount/getBanks.do",
        	"params" : {"province" : provinceCode , "city" : cityCode},
        	"success" : function(result){
        		if(result.success.toString() == "true"){//success

        			//销毁组件
        			if($("#weixinOpenStep2Page div[name='mainBank']>ul").length > 0){
        				$("#weixinOpenStep2Page div[name='mainBank']>ul").mobiscroll("destroy");
        				$("#weixinOpenStep2Page div[name='mainBank']>ul").remove();
        				$("#weixinOpenStep2Page div[name='mainBank']>input[type='hidden']").val("");
        			}

        			var bankList = result.resultObject;
        			var bankListHtml = "<ul style='display:none;'>";
        			$.each(bankList,function(index,element){
        				bankListHtml += "<li data-code='"+element.bankCode+"' data-val='"+element.bankName+"'>"+element.bankName+"</li>";
        			});
        			bankListHtml += "</ul>";
        			$("#weixinOpenStep2Page div[name='mainBank']").prepend(bankListHtml);

					$("#weixinOpenStep2Page div[name='mainBank']").children("ul").mobiscroll().treelist({
			            "theme": "ios",
			            "display": "bottom",
			            "lang": "zh",
			            "placeholder": "请选择",
			            "onSelect" : function(valueText,inst){
			            	var codeArray = [];
			            	var $ul = $this = $(this);
			            	$.each(valueText.split("-"),function(index,value){
			            		var $li = $ul.children("li[data-val='"+value+"']");
			            		codeArray.push($li.attr("data-code"));  //data会进行类型转换
			            		$ul = $li.children("ul").eq(0);
			            	});
			            	$this.parent().find("input[type='hidden']").val(codeArray.join(","));

			            	//清空级联数据
			            	$("#weixinOpenStep2Page input[name='branchBank']").val("");
			            	$("#weixinOpenStep2Page input[name='contactLine']").val("");

			            	listen4Submit();
			            }
			        });

			        callback();

        		}else{//business error
        			DialogUtil.dialogWarn(result.msg);
        		}
        	},
        	"error" : function(){//not 200
        		DialogUtil.dialogWarn("请求失败，请稍候重试");
        	}
        });
	}

	//控制“下一步”是否可点击
	function listen4Submit(){
		var accountType = $("#weixinOpenStep2Page div[name='accountType'] input[type='hidden']").val();	//账户类型
		var bankDistrict = $("#weixinOpenStep2Page div[name='bankDistrict'] input[type='hidden']").val();	//开户行所在地区
		var mainBank = $("#weixinOpenStep2Page div[name='mainBank'] input[type='hidden']").val();	//开户行编码
		var branchBank = $("#weixinOpenStep2Page input[name='branchBank']").val();	//支行名称
		var contactLine = $("#weixinOpenStep2Page input[name='contactLine']").val();	//联行号
		var bankAccount = $("#weixinOpenStep2Page input[name='bankAccount']").val();	//银行帐号
		
		var identityCard = $("#weixinOpenStep2Page input[name='identityCard']").val();	//身份证
		//==手机号/身份证正反面已经转移到第一步中
		// var mobile = $("#weixinOpenStep2Page input[name='mobile']").val();	//手机号
		// var weixinImgUrl4Front = $("#weixinOpenStep2Page li[name='frontPicture']").attr("weixinImgUrl"); //正面：微信
		// var weixinImgUrl4Back = $("#weixinOpenStep2Page li[name='backPicture']").attr("weixinImgUrl"); //反面：微信

		if(accountType && bankDistrict && mainBank && branchBank && contactLine && bankAccount && identityCard ){
			if(accountType == Constants.weixin.ACCOUNT_TYPE.person){
				var username4Person = $("#weixinOpenStep2Page input[name='username4Person']").val();	//开户人姓名
				if(username4Person){
					$("#weixinOpenStep2Page .header li.right").removeClass("disabled");
					return;
				}
			}else if(accountType == Constants.weixin.ACCOUNT_TYPE.company){
				var companyName4Company = $("#weixinOpenStep2Page input[name='companyName4Company']").val();	//收款单位
				var pricipal4Company = $("#weixinOpenStep2Page input[name='principal4Company']").val();	//负责人
				if(companyName4Company && pricipal4Company){
					$("#weixinOpenStep2Page .header li.right").removeClass("disabled");
					return;
				}
			}
		}

		$("#weixinOpenStep2Page .header li.right").addClass("disabled");
	}

	//页面事件绑定
	function bindEvents4Page(){

		//返回
		$(document).on("click","#weixinOpenStep2Page .header .back",function(e){
			var cache = CommonUtil.takeOutParamObject() || {};
			cache.backFrom = "weixinOpenStep2Page";
			CommonUtil.injectParamObject(cache);
			$.router.back();
		});

		//监听输入，控制下一步是否可点击
		var listenFormStr = "#weixinOpenStep2Page input[name='contactLine']," + 
							"#weixinOpenStep2Page input[name='bankAccount']," + 
							"#weixinOpenStep2Page input[name='username4Person']," + 
							"#weixinOpenStep2Page input[name='companyName4Company']," + 
							"#weixinOpenStep2Page input[name='principal4Company']," + 
							"#weixinOpenStep2Page input[name='mobile']," + 
							"#weixinOpenStep2Page input[name='identityCard']";
		$(document).on("input",listenFormStr,function(e){
			listen4Submit();
		});
		$(document).on("clearInput","#weixinOpenStep2Page .zhk-list_gb",function(e){
			listen4Submit();
		});
		

		//开户银行
		$(document).on("click","#weixinOpenStep2Page div[name='mainBank']",function(e){
			var bankDistrict = $("#weixinOpenStep2Page div[name='bankDistrict'] input[type='hidden']").val();
			if(!bankDistrict){
				DialogUtil.dialogWarn("请您先选择开户行地区");
				return;
			}
		});

		//支行名称
		$(document).on("click","#weixinOpenStep2Page div[name='branchBank']",function(e){
			var bankDistrict = $("#weixinOpenStep2Page div[name='bankDistrict'] input[type='hidden']").val();
			if(!bankDistrict){
				DialogUtil.dialogWarn("请您先选择开户银行");
				return;
			}

			var mainBank = $("#weixinOpenStep2Page div[name='mainBank'] input[type='hidden']").val();
			if(!mainBank){
				DialogUtil.dialogWarn("请您先选择开户银行");
				return;
			}

			var cache = CommonUtil.takeOutParamObject() || {};
			cache.bankDistrict = bankDistrict;
			cache.mainBank = mainBank;
			CommonUtil.injectParamObject(cache);
			$.router.load("weixin_branch_bank_search.html",true);
		});

		//身份证照片
		$(document).on("click","#weixinOpenStep2Page input[type='file']",function(e){//阻止file默认行为
			e.preventDefault();
		});	
		$(document).on("click","#weixinOpenStep2Page li.picture",function(e){//上传
			if($(e.target).hasClass("zhk-list_gb"))	return;

			uploadPicture($(this));
		});	
		$(document).on("click","#weixinOpenStep2Page .picture .zhk-list_gb",function(e){//删除
			var $li = $(this).parents("li.picture");
			displayPicture($li,"hide");

			$li.attr("yzImgUrl","");
			$li.attr("weixinImgUrl","");

			listen4Submit();
		});

		//提交
		$(document).on("click","#weixinOpenStep2Page .header a[name='submit']",function(e){
			if($(this).parents(".right").hasClass("disabled"))	return;

			submitWeixinPay();
		});

	}

	//身份证显示
	function displayPicture(target,showOrHide){

		if(showOrHide == "show"){
			target.find("div.upload-before").hide();
			target.find("div.upload-after").show();
		}else if(showOrHide == "hide"){
			target.find("div.upload-before").show();
			target.find("div.upload-after").hide();
		}
	}

	//上传身份证照片
	function uploadPicture(target){

		$.actions([[{
			"text" : "相册",
			"onClick" : function(){

				//选择
				
				AppUtil.call(AppUtil.APIS.SELECT_PICTURE,{"compress":{"sizeLimit":"500","unit":"K"},"format":"JPG","maxNum":"1"},function(selectResult){
					if(selectResult.success.toString() == "true"){
						var filePath = selectResult.resultObject[0];

						//上传
						common.loading("上传中");
						AppUtil.call(AppUtil.APIS.UPLOAD_PICTURE,{"url":App.serverUrl+"/app/img/upload.do","file":filePath,"data":{"shopId":pageVariables.shopId,"uploadType":target.attr("uploadType")}},function(uploadResult){
							common.closeLoading();
							if(uploadResult.success.toString() == "true" && uploadResult.resultObject.success.toString() == "true"){
								target.attr("yzImgUrl",uploadResult.resultObject.resultObject.imageUrl);
								target.attr("weixinImgUrl",uploadResult.resultObject.resultObject.thirdPartyImageUrl);

								//显示图片
								target.find("img").attr("src",filePath);
								displayPicture(target,"show");

								listen4Submit();
							}else{
								var msg = "";
								if(uploadResult.success.toString() == "false"){
									msg = uploadResult.msg;
								}else if(uploadResult.resultObject.success.toString() == "false"){
									msg = uploadResult.resultObject.msg;
								}
								DialogUtil.dialogWarn(msg);
							}
						});
					}else{
						DialogUtil.dialogWarn(selectResult.msg);
					}
				})
			}
		},{
			"text" : "拍照",
			"onClick" : function(){

				//拍照
				AppUtil.call(AppUtil.APIS.TAKE_PICTURE,{"compress":{"sizeLimit":"500","unit":"K"},"format":"JPG","maxNum":"1"},function(selectResult){
					if(selectResult.success.toString() == "true"){
						var filePath = selectResult.resultObject;

						//上传
						common.loading("上传中");
						AppUtil.call(AppUtil.APIS.UPLOAD_PICTURE,{"url":App.serverUrl+"/app/img/upload.do","file":filePath,"data":{"shopId":pageVariables.shopId,"uploadType":target.attr("uploadType")}},function(uploadResult){
							common.closeLoading();
							if(uploadResult.success.toString() == "true" && uploadResult.resultObject.success.toString() == "true"){
								target.attr("yzImgUrl",uploadResult.resultObject.resultObject.imageUrl);
								target.attr("weixinImgUrl",uploadResult.resultObject.resultObject.thirdPartyImageUrl);

								//显示图片
								target.find("img").attr("src",filePath);
								displayPicture(target,"show");

								listen4Submit();
							}else{
								var msg = "";
								if(uploadResult.success.toString() == "false"){
									msg = uploadResult.msg;
								}else if(uploadResult.resultObject.success.toString() == "false"){
									msg = uploadResult.resultObject.msg;
								}
								DialogUtil.dialogWarn(msg);
							}
						});
					}else{
						DialogUtil.dialogWarn(selectResult.msg);
					}
				})
			}
		}],[{
			"text" : "取消",
			"color" : "danger",
			"onClick" : function(){
			}
		}]]);

	}

	//提交开通微信支付
	function submitWeixinPay(){

		//表单参数
		var accountType = $("#weixinOpenStep2Page div[name='accountType'] input[type='hidden']").val();	//账户类型
		var accountTypeText = $("#weixinOpenStep2Page div[name='accountType']>ul").mobiscroll("getVal");
		var bankDistrict = $("#weixinOpenStep2Page div[name='bankDistrict'] input[type='hidden']").val();	//开户行所在地区
		var bankDistrictText = $("#weixinOpenStep2Page div[name='bankDistrict']>ul").mobiscroll("getArrayVal");
		var mainBank = $("#weixinOpenStep2Page div[name='mainBank'] input[type='hidden']").val();	//开户行编码
		var mainBankText = $("#weixinOpenStep2Page div[name='mainBank']>ul").mobiscroll("getVal");
		var branchBank = $("#weixinOpenStep2Page input[name='branchBank']").val();	//支行名称
		var contactLine = $("#weixinOpenStep2Page input[name='contactLine']").val().trim();	//联行号
		var bankAccount = $("#weixinOpenStep2Page input[name='bankAccount']").val().trim();	//银行帐号
		var username4Person = "";	//开户人姓名
		var companyName4Company = "";	//收款单位
		var pricipal4Company = "";	//负责人
		var identityCard = $("#weixinOpenStep2Page input[name='identityCard']").val().trim();	//身份证
		var address = $("#weixinOpenStep2Page input[name='address']").val().trim();//开户人地址
		var invitationCode = $("#weixinOpenStep2Page input[name='invitationCode']").val().trim();
		//var mobile = $("#weixinOpenStep2Page input[name='mobile']").val().trim();	//手机号
		//var yzImgUrl4Front = $("#weixinOpenStep2Page li[name='frontPicture']").attr("yzImgUrl"); //正面：云纵
		//var weixinImgUrl4Front = $("#weixinOpenStep2Page li[name='frontPicture']").attr("weixinImgUrl"); //正面：微信
		//var yzImgUrl4Back = $("#weixinOpenStep2Page li[name='backPicture']").attr("yzImgUrl");	//反面：云纵
		//var weixinImgUrl4Back = $("#weixinOpenStep2Page li[name='backPicture']").attr("weixinImgUrl"); //反面：微信

		//校验：账户类型
		if(!accountType){
			DialogUtil.dialogWarn("请选择账户类型");
			return;
		}

		//校验：开户行地区
		if(!bankDistrict){
			DialogUtil.dialogWarn("请选择开户行地区");
			return;
		}

		//校验：开户银行
		if(!mainBank){
			DialogUtil.dialogWarn("请选择开户银行");
			return;
		}

		//校验：支行名称
		if(!branchBank){
			DialogUtil.dialogWarn("请选择支行名称");
			return;
		}

		//校验：联行号
		if(contactLine.length == 0){
			DialogUtil.dialogWarn("请填写联行号");
			return;
		}
		if(!/^\d{12}$/.test(contactLine)){
			DialogUtil.dialogWarn("联行号必须为12位数字");
			return;
		}

		//校验：银行帐号
		if(bankAccount.length == 0){
			DialogUtil.dialogWarn("请填写银行账号");
			return;
		}
		if(!/^\d{1,32}$/.test(bankAccount)){
			DialogUtil.dialogWarn("请填写有效的银行账号");
			return;
		}

		if(address.length==0){
			DialogUtil.dialogWarn("请填写开户人地址");
			return;
		}

		if(accountType == Constants.weixin.ACCOUNT_TYPE.person){//个人

			//校验：开户人姓名
			username4Person = $("#weixinOpenStep2Page input[name='username4Person']").val().trim();
			if(username4Person.length == 0){
				DialogUtil.dialogWarn("请填写开户人姓名");
				return;
			}
			if(!/^[\u4e00-\u9fa5]+$/.test(username4Person)){
				DialogUtil.dialogWarn("开户人姓名仅允许输入中文");
				return;
			}
			if(CommonUtil.countBytes(username4Person,2) > 32){
				DialogUtil.dialogWarn("开户人姓名输入过长");
				return;
			}
		}else if(accountType == Constants.weixin.ACCOUNT_TYPE.company){//企业

			//校验：收款单位
			companyName4Company = $("#weixinOpenStep2Page input[name='companyName4Company']").val().trim();
			if(companyName4Company.length == 0){
				DialogUtil.dialogWarn("请填写收款单位");
				return;
			}
			if(!/^[\u4e00-\u9fa5]+$/.test(companyName4Company)){
				DialogUtil.dialogWarn("收款单位仅允许输入中文");
				return;
			}
			if(CommonUtil.countBytes(companyName4Company,2) > 32){
				DialogUtil.dialogWarn("收款单位输入过长");
				return;
			}

			//校验：负责人
			pricipal4Company = $("#weixinOpenStep2Page input[name='principal4Company']").val().trim();
			if(pricipal4Company.length == 0){
				DialogUtil.dialogWarn("请填写负责人姓名");
				return;
			}
			if(!/^[\dA-Za-z\u4e00-\u9fa5]+$/.test(pricipal4Company)){
				DialogUtil.dialogWarn("负责人仅允许输入中文、英文、数字");
				return;
			}
			if(CommonUtil.countBytes(pricipal4Company,2) > 32){
				DialogUtil.dialogWarn("负责人输入过长");
				return;
			}
		}

		// //校验：手机号
		// if(mobile.length == 0){
		// 	DialogUtil.dialogWarn("请填写手机号");
		// 	return;
		// }
		// if(!/^[1][3578][0-9]{9}$/.test(mobile)){
		// 	DialogUtil.dialogWarn("请填写有效的手机号");
		// 	return;
		// }
		
		//校验：身份证号码
		if(identityCard.length == 0){
			DialogUtil.dialogWarn("请填写身份证号码");
			return;
		}
		if(!/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/.test(identityCard) && !/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(identityCard)){
			DialogUtil.dialogWarn("请填写有效的身份证号码");
			return;
		}

		// //校验：身份证照片
		// if(!yzImgUrl4Front){
		// 	DialogUtil.dialogWarn("请上传正面身份证");
		// 	return;
		// }
		// if(!yzImgUrl4Back){
		// 	DialogUtil.dialogWarn("请上传反面身份证");
		// 	return;
		// }

		//提交
		var params = CommonUtil.takeOutParamObject() || {};
		var stepOne = params.stepOne;
		var stepTwo = {};
		stepTwo.type = pageVariables.type;	//1-新增；2-编辑
		stepTwo.accountType = accountType; //账户类型
		stepTwo.accountTypeName = accountTypeText;
		stepTwo.bankProvince = bankDistrict.split(",")[0]; //开户行所在省份
		stepTwo.bankCity = bankDistrict.split(",")[1]; //开户行所在市
		stepTwo.bankProvinceName = bankDistrictText[0];
		stepTwo.bankCityName = bankDistrictText[1];
		stepTwo.bankId = mainBank; //主行编码
		stepTwo.bankMainName = mainBankText;
		stepTwo.bankName = branchBank; //支行名称
		stepTwo.accountCode = bankAccount; //银行账号
		stepTwo.contactLine = contactLine; //联行号
		if(accountType == Constants.weixin.ACCOUNT_TYPE.person){
			stepTwo.accountName = username4Person;//开户人姓名
			stepTwo.principal = username4Person;
		}else if(accountType == Constants.weixin.ACCOUNT_TYPE.company){
			stepTwo.accountName = companyName4Company;//收款单位
			stepTwo.principal = pricipal4Company; //负责人
		}
		
		stepTwo.idCard = identityCard; //身份证号码
		stepTwo.address = address;//开户人地址
		stepTwo.invitationCode = invitationCode;
		// stepTwo.principalMobile = mobile; //手机号
		// stepTwo.yzImageFrontUrl = yzImgUrl4Front; //正面：云纵
		// stepTwo.identityCardPicFront = weixinImgUrl4Front; //正面：微信
		// stepTwo.yzImageReverseUrl = yzImgUrl4Back; //反面：云纵
		// stepTwo.identityCardPicContrary = weixinImgUrl4Back; //反面：微信

		var submitData = $.extend({"shopId" : pageVariables.shopId},stepOne,stepTwo);
		common.loading("提交中");
		AppUtil.call(
		// testApi.testSubmit(
			AppUtil.APIS.SEND_HTTP_REQUEST,
			{
				"type":"POST",
				"url":App.serverUrl+"/app/wxAccount/apply.do",
				"data":JSON.stringify(submitData)
			},
			function(submitResult){
				common.closeLoading();

				var cache = CommonUtil.takeOutParamObject() || {};
				cache.shopId = pageVariables.shopId;
				CommonUtil.injectParamObject(cache);

				if(submitResult.success.toString() == "true" && submitResult.resultObject.success.toString() == "true"){//成功
					$.router.load("weixin_open_success.html");
				}else{//失败
					var errorMsg = "";
					if(submitResult.success.toString() == "false"){
						errorMsg = submitResult.msg;
					}else if(submitResult.resultObject.success.toString() == "false"){
						errorMsg = submitResult.resultObject.msg;
					}
					
					var cache = CommonUtil.takeOutParamObject() || {};
					cache.errorMsg = errorMsg;
					CommonUtil.injectParamObject(cache);
					$.router.load("weixin_open_error.html");
				}
			}
		);
	}

	/**
	 * 测试接口
	 * @type {Object}
	 */
	var testApi = {

		"testSubmit" : function(apiName,params,callback){//提交
			callback({
				"code" : "0",
				"msg" : "",
				"resultObject" : {
					"code" : "0",
					"msg" : "",
					"success" : true,
					"resultObject" : ""
				},
				"success" : true
			});
		},

		"testGetBankList" : function(options){//获取开户银行列表
			options.success({
				"success" : true,
				"resultObject" : [
					{"bankCode" : "001" , "bankName" : "中国银行"},
					{"bankCode" : "002" , "bankName" : "中国工商银行"},
					{"bankCode" : "003" , "bankName" : "中国建设银行"},
					{"bankCode" : "004" , "bankName" : "中国农业银行"}
				]
			});
		}
	};

})(document, window);